国外有很多优质资源,但国内的外网访问体验一向不好。不少内容因为国外服务器距离远而下载慢,甚至有的直接无法在国内访问,而在 Linux 下,很多优秀工具或网站都是外国人开发的,问题则尤为明显,这个时候如果能通过国外的代理网络访问可以大幅提高访问速度。
很多命令都提供自带的代理网络配置方法,可以在使用命令时直接配置参数,甚至有一些工具可以设置全局参数,这样就不用每次使用都要添加代理配置。当然了,也有一些命令暂时没有配置网络代理的功能,那么就可以通过第三方工具,例如 proxy4chains,单独为此次命令运行配置代理网络环境。
apt
临时使用
sudo apt-get -o Acquire::http::proxy="http://127.0.0.1:8000/" update特定源代理
sudo tee -a /etc/apt/apt.conf.d/10proxy << EOF >/dev/nullAcquire::https::Proxy::download.sublimetext.com "http://127.0.0.1:10801/";
Acquire::https::Proxy::ppa.launchpadcontent.net "http://127.0.0.1:10801/";
Acquire::https::Proxy::packages.mozilla.org "http://127.0.0.1:10801/";
Acquire::https::Proxy::deb.debian.org "http://127.0.0.1:10801/";
EOF
上面这几个源也是我常用的代理源。
全部走代理
sudo tee -a /etc/apt/apt.conf.d/10proxy << EOF >/dev/null
Acquire::http::Proxy "http://127.0.0.1:10801";
Acquire::https::Proxy "http://127.0.0.1:10801";
EOF说明推荐在遇到连接慢或者连不上的源时,再针对这个源添加代理,如果全部走代理,那国内的源也会走代理,反而会变慢。
git
设置
git config --global https.proxy http://127.0.0.1:10801
git config --global http.proxy http://127.0.0.1:10801查看
git config --global --get https.proxy
git config --global --get https.proxy取消
git config --global --unset http.proxy
git config --global --unset https.proxynpm
设置代理
npm config set proxy http://127.0.0.1:10801
npm config set proxy http://127.0.0.1:10801取消代理
npm config delete proxy
npm config delete https-proxynpm 除了设置代理外,也可以使用国内源,优点是不需要代理,缺点就是国内源是镜像官方源的,偶尔会抽风。
切换淘宝源
npm config set registry https://registry.npm.taobao.org换回官方仓库
npm config set registry https://registry.npmjs.org/说明使用淘宝源有时会遇到报错:npm ERR! Cannot read properties of null (reading 'pickAlgorithm'),切换回官方源即可。
yarn
yarn 的设置跟 npm 差不多。
设置
yarn config set proxy http://127.0.0.1:10801
yarn confit set https-proxy http://127.0.0.1:10801查看
yarn config list取消
yarn config delete proxy
yarn config delete https-proxy切换淘宝源
yarn config set registry https://registry.npm.taobao.orgwget
wget 本身没有专门设置代理的命令行参数,但是有一个 -e 参数,可以在命令行上指定一个原本出现在 .wgetrc 中的设置。
# 针对 https 资源
wget -e "https_proxy=http://127.0.0.1:10801"针对 http 资源
wget -e "http_proxy=http://127.0.0.1:10801"
也可以直接通过 export https_proxy=socks5://127.0.0.1:10800; wget 链接 的方式走代理,这种方式其实就是配置了终端的代理环境。
Go
临时
export GOPROXY=https://goproxy.io,direct永久
go env -w GOPROXY=goproxy.cn,direct取消代理
go env -w GOPROXY=direct或设置系统代理
export http_proxy=http://127.0.0.1:10801
export https_proxy=http://127.0.0.1:10801Curl
临时
curl -x socks5://127.0.0.1:10800 $url</code></pre><p>永久</p><pre><code class="lang-bash">echo 'socks5 = "127.0.0.1:10800"' >> ~/.curlrc</code></pre><p>临时不用</p><pre><code class="lang-bash">curl --noproxy "*" $urlDocker
docker 需要创建一个配置文件才行,且 HTTP 和 HTTPS 需要分别用一个配置文件。
sudo mkdir -p /etc/systemd/system/docker.service.dsudo tee -a /etc/systemd/system/docker.service.d/proxy.conf << EOF > /dev/null
[Service]
Environment="HTTP_PROXY=http://127.0.0.1:10801"
Environment="HTTPS_PROXY=http://127.0.0.1:10801"
Environment="NO_PROXY=localhost,127.0.0.1"
EOF
添加完后重启一下 docker:
sudo systemctl daemon-reload
sudo systemctl restart docker
Int的笔记